#include <sys/syscall.h>
#include <sys/types.h> /* pid_t */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>  /* _exit, fork */
#include <errno.h>   /* errno */

#define __NR_logcalls   350

int logcalls(char * path)
{
        return (int) syscall(__NR_logcalls, path);
}

int main (int argc, char *argv[])
{
        if (argc != 4)
        {
                printf("Invalid input format.\nFormat: logcalls [path] [prog] [arg]\n");
                exit(0);
        }

        if ( logcalls(argv[1]) == 0 )
        {
                printf("PID: %d\n", getpid());
                printf("Logging open and exec system calls to path: %s\n", argv[1]);
        }
        else
        {
                printf("logcalls failed, please check /var/log/syslog\n");
                exit(0);
        }

        char * prog = argv[2];          // program
        char * arg = argv[3];           // program arguments
        char * args_n[3];

        args_n[0] = prog;
        args_n[1] = arg;
        args_n[2] = NULL;

        execv( argv[2], args_n );

        exit(0);
}
